
function corr = areaOFinterest(im)

    tmp = bwareaopen(im,40);
    L = bwlabel(tmp,8);
    L2 = SameGrounp(L,20);
    STATS = regionprops(L2,'BoundingBox','Area') ;
    corr = STATS;

end


function im = SameGrounp(im,dis)

    im_Per = bwmorph(im,'remove');

    im_size = size(im);

    for i = 1:im_size(1)
        for j = 1:im_size(2)
            if im_Per(i,j) == 0
                continue;
            end
            
            s_i_l = i-dis;
            if s_i_l < 1
                s_i_l = 1;
            end
            s_i_u = i+dis;
            if s_i_u > im_size(1)
                s_i_u = im_size(1);
            end

            s_j_l = j - dis;
            if s_j_l < 1
                s_j_l = 1;
            end
            s_j_u = j + dis;
            if s_j_u > im_size(2)
                s_j_u = im_size(2);
            end

            for s_i = s_i_l:s_i_u
                for s_j =  s_j_l:s_j_u
                    if im(s_i,s_j) == 0
                        continue;
                    end
                    if im(i,j) ~= im(s_i,s_j)
                        im = ReGroup(im,im(s_i,s_j),im(i,j));
                    end
                end
            end           
                   
        end
    end
    

end

function im = ReGroup(im,oldG,newG)
    im_size = size(im);
    
    for i = 1:im_size(1)
        for j = 1:im_size(2)
            if(im(i,j) == oldG)
                im(i,j) = newG;
            end
        end
    end
end




